<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\admin\service\ModuleService;
use app\common\libs\module\ModuleInstall;
use app\common\libs\module\ModuleUninstall;
use app\Request;
use think\facade\View;

/**
 * 模块管理
 *
 * @Author tanruizheng
 * @DateTime 2021-07-30
 */
class Module extends AdminController
{
    /**
     * 模块列表
     *
     * @Author tanruizheng
     * @DateTime 2021-07-30
     * @return void
     */
    public function index(Request $request){
        if($request->param('_action') == 'getModuleList'){
            $res = ModuleService::getModuleList();
            return json($res);
        }
        return View::fetch('index');
    }

    /**
     * 模块安装
     *
     * @Author tanruizheng
     * @DateTime 2021-07-30
     * @return void
     */
    public function install(Request $request){
        $module = $request->param('module');
        if(!$module){
            return self::createFail('参数错误');
        }
        $moduleInstall = new ModuleInstall($module);
        $res = $moduleInstall->run();
        return json($res);
    }

    /**
     * 模块卸载
     *
     * @Author tanruizheng
     * @DateTime 2021-07-30
     * @return void
     */
    public function unInstall(Request $request){
        $module = $request->param('module');
        if(!$module){
            return self::createFail('参数错误');
        }
        $moduleUnInstall = new ModuleUninstall($module);
        $res = $moduleUnInstall->run();
        return json($res);
    }
}
